﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>预约单管理</title>
    <#include "/common/link.ftl">
    <script>
        $(function () {
            $('.input-date').datepicker({
                format: 'yyyy-mm-dd', //格式
                language: 'zh-CN', //中文
                autoclose: true,//选择后自动关闭
                //showMeridian:true, //是否显示上下午
                minView: 2,//精确到哪位
            });


            $('.btn-input').click(function () {

                //清空表单数据
                //$('#editForm').clearForm(true);
                $('input[name]').val('');
                //再设置默认值回去
                $("#editForm input[name='status']").val(1);
                $("#category").val(-1);
                $("#businessId").val(-1);
                $("#businessModal").val(-1);
                $("#editForm textarea[name='info']").val('');


                //编辑数据回显
                var data = $(this).data('json');


                if (data) {
                    console.log(data);
                    $('#editForm input[name=id]').val(data.id);
                    $("#editForm select[name='business.id']").val(data.businessId);
                    $("#editForm input[name='status']").val(data.status);
                    $("#editForm input[name='appointmentTime']").val(data.appointmentTime);
                    $("#editForm input[name='contactName']").val(data.contactName);
                    $("#editForm input[name='contactTel']").val(data.contactTel);
                    $("#editForm textarea[name='info']").val(data.info);



                    //业务回显
                    $("#category").val(data.categoryParentId);
                    console.log(data.categoryParentId);

                    var html = "<option value='-1'>请选择预约业务</option>";
                    $.get("/systemDictionary/queryByParentId", {parentId: data.categoryParentId}, function (data1) {
                        $.each(data1, function (index, item) {
                            html += "<option value='" + item.id + "'>" + item.name + "</option>";
                        });
                        $('#businessModal').html(html);
                        $('#businessModal').val(data.categoryChildId);
                    })
                }

                $('#editModal').modal('show')
            });


            //业务选中
            $('#category').change(function () {
                var value = $(this).val();
                var html = "<option value='-1'>请选择预约业务</option>";
                if (value < 0) {
                    $("#businessModal").html(html);
                    return;
                }
                $.get("/systemDictionary/queryByParentId", {parentId: value}, function (data) {
                    $.each(data, function (index, item) {
                        html += "<option value='" + item.id + "'>" + item.name + "</option>";
                    });
                    $('#businessModal').html(html)

                })
            });


            //预约修改状态
            $('.btn-status').click(function () {
                var status = $(this).data("status");
                var id = $(this).data("id");
                var msg = "是否与客户确认取消本次预约么?";
                if (status == 1) {
                    msg = "是否与客户已经确认预约信息无误了么?"
                }
                Swal.fire({
                    title: msg,
                    text: "该操作不可撤销",
                    icon: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '确定',
                    cancelButtonText: '取消'
                }).then((result) => {
                    if (result.value) {
                        // 点了确定做什么，由开发者决定
                        console.log(msg);
                        console.log(id);
                        console.log(status);
                        $.get("/appointment/updateStatus", {id: id, status: status}, function (data) {
                            if (data.success){
                                window.location.reload();
                            }else {
                                console.log(data.msg);
                            }
                        });
                        //window.location.href="/appointment/updateStatus?id="+id+"&status="+status;
                    }
                });
            });

            //修改到店状态
            $('.btn-consume').click(function () {
                var id =$(this).data("id");
                var status =$(this).data("status");

                Swal.fire({
                    title: "温馨提示",
                    text: "是否确定客户已经到店",
                    icon: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '是',
                    cancelButtonText: '否'
                }).then((result) => {
                    if (result.value) {
                        // 点了确定做什么，由开发者决定
                        Swal.fire({
                            title: "温馨提示",
                            text: "客户是否进行消费",
                            icon: 'warning',
                            showCancelButton: true,
                            confirmButtonColor: '#3085d6',
                            cancelButtonColor: '#d33',
                            confirmButtonText: '有消费',
                            cancelButtonText: '无消费'
                        }).then((result) => {
                            if (result.value) {
                                //到店有消费,修改状态
                                window.location.href="/consumption/save?aid="+id;
                            }else {
                                //到店无消费,更改状态为归档中
                                $.get("/appointment/updateStatus",{id:id,status: status} ,function (data) {
                                    if (data.success){
                                        window.location.reload();
                                    }else {
                                        console.log(data.msg);
                                    }
                                });
                                //window.location.href="/appointment/updateStatus?id="+id;
                            }
                        });


                    }else {
                        //无到店
                    }
                });
            });


        });

    </script>
</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="appointment"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>预约单管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <div style="margin: 20px 0px 0px 10px">
                    <form class="form-inline" id="searchForm" action="/appointment/list" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <div class="form-group">
                            <label>预约单流水号</label>
                            <input type="text" class="form-control" placeholder="请输入预约单流水号" name="ano"
                                   value="${qo.ano!}">
                        </div>

                        <div class="form-group">
                            <label>预约单状态</label>
                            <select class="form-control" id="status" name="status">
                                <option value="-1">全部</option>
                                <option value="0">待确认</option>
                                <option value="1">履行中</option>
                                <option value="2">消费中</option>
                                <option value="3">归档中</option>
                                <option value="4">废弃</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>门店查询</label>
                            <select class="form-control" name="businessId">
                                <option value="-1">请选择门店</option>
                                <#list businesses as b>
                                    <option value="${b.id!}">${b.name!}</option>
                                </#list>
                            </select>
                            <script>
                                $('#businessId').val(${qo.businessId!});
                                $('#status').val(${qo.status!});
                            </script>
                        </div>
                        <div class="form-group">
                            <label>客户名称</label>
                            <input type="text" class="form-control" placeholder="请输入客户名称" name="contactName"
                                   value="${qo.contactName!}">
                        </div>

                        <div class="form-group">
                            <label>客户手机号</label>
                            <input type="text" class="form-control" placeholder="请输入客户手机号" name="contactTel"
                                   value="${qo.contactTel!}">
                        </div>

                        <br/>
                        <br/>

                        <div class="form-group">
                            <label>预约时间查询：</label>
                            <input placeholder="请输入开始时间" type="text" class="form-control input-date" name="beginDate"
                                   value="${((qo.beginDate)?string("yyyy-MM-dd"))!}"/> -
                            <input placeholder="请输入结束时间" type="text" class="form-control input-date" name="endDate"
                                   value="${((qo.endDate)?string("yyyy-MM-dd"))!}"/>
                        </div>

                        <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span>
                            查询
                        </button>

                        <a href="#" class="btn btn-success btn-input">
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                    </form>

                </div>
                <div class="box-body table-responsive ">
                    <table class="table table-hover table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>流水号</th>
                            <th>业务分类</th>
                            <th>预约说明</th>
                            <th>预约时间</th>
                            <th>客户名称</th>
                            <th>联系方式</th>
                            <th>预约门店</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <#list pageInfo.list as appointment>
                            <tr>
                                <td>${appointment_index+1}</td>
                                <td>${appointment.ano!}</td>
                                <td>${appointment.category.name!}</td>
                                <td>${appointment.info}</td>
                                <td>${((appointment.appointmentTime)?string("yyyy-MM-dd"))!}</td>
                                <td>${appointment.contactName!}</td>
                                <td>${appointment.contactTel!}</td>
                                <td>${appointment.business.name!}</td>
                                <td>${appointment.statusDisplay!}</td>
                                <td>
                                    <a href="#" class="btn btn-info btn-xs btn-input"
                                       data-json='${appointment.toJson()}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                    <a href="#" class="btn btn-xs btn-primary btn-status" data-status="1"
                                       data-id="${appointment.id}">
                                        <span class="glyphicon glyphicon-phone-alt"></span> 确认预约</a>
                                    <a href="#" class="btn btn-xs btn-danger btn-status" data-status="4"
                                       data-id="${appointment.id}">
                                        <span class="glyphicon glyphicon-remove"></span> 取消预约</a>
                                    <a href="#" class="btn btn-success btn-xs btn-consume" data-status="3" data-id="${appointment.id!}">
                                        <span class="glyphicon glyphicon-shopping-cart"></span> 确认到店
                                    </a>
                                </td>
                            </tr>
                        </#list>
                        </tbody>
                    </table>
                    <!--分页-->
                    <#include "/common/page.ftl">
                </div>

            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>


<#-- 文件上传模态框 -->
<!--模态框-->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
            </div>

            <form id="editForm" action="/appointment/saveOrUpdate" method="post">
                <div class="modal-body">
                    <input type="hidden" name="id">
                    <#--默认状态是1:履行中-->
                    <input type="hidden" name="status" value="1">
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">预约门店：</label>
                        <div class="col-sm-7">
                            <select class="form-control" name="business.id" id="businessId">
                                <option value="-1">请选择预约门店</option>
                                <#list businesses as b>
                                    <option value="${b.id!}">${b.name!}</option>
                                </#list>

                            </select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">预约时间：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control input-date" placeholder="请输入预约时间"
                                   name="appointmentTime"/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">业务分类：</label>
                        <div class="col-sm-7">
                            <select class="form-control category" name="categoryParentId" id="category">
                                <option value="-1">请选择预约业务分类</option>
                                <#list category as c>
                                    <option value="${c.id!}">${c.name!}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">预约业务：</label>
                        <div class="col-sm-7">
                            <select class="form-control business" name="category.id" id="businessModal">
                                <option value="-1">请选择预约业务</option>

                            </select>
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">联系人：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control"
                                   placeholder="请输入联系人" name="contactName">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">联系电话：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control"
                                   placeholder="请输入联系电话" name="contactTel">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">预约说明：</label>
                        <div class="col-sm-7">
                            <textarea type="text" class="form-control"
                                      placeholder="请输入预约说明" name="info"></textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary btn-submit">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>


</body>
</html>
